package cn.topcode.unicorn.utils.http;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;

public abstract class HttpRequestCallback {

    public void completed(HttpResponse response) {
        try {
            int statusCode = response.getStatusLine().getStatusCode();
            switch(statusCode) {
            case 200:
                ok(response.getAllHeaders(),response.getEntity());
                break;
            case 404:
                notfound();
                break;
                default:
                    other(response);
                    break;
            }
        }catch(Exception e) {
            failed(e);
        }
    }
    
    public abstract void ok(Header[] headers, HttpEntity httpEntity) throws Exception;
    
    public void notfound() {}
    
    public void other(HttpResponse response) {}

    public void failed(Exception ex) {}

}
